#include "ICMPv4_TYPE.h"
#include "ICMPv4config.h"
#include "AbstractionAPI.h"
#include <stdio.h>
#include <string.h>
#define IP_DUT "192.168.1.211" //"10.98.4.23"
#define IP_TESTER "192.168.1.175"
#define MAC "62:66:64:61:AA:17"
#include "TestabilityProtocol_api.h"
#include "TestabilityProtocol_Intern.h"
typedef unsigned short int uint16;
typedef unsigned char uint8;
void stoiIP(const char *in_s, uint8_t *out_ip) 
{
    char temp_c;
    uint8_t octet_i = 0;
    uint8_t octet_p = 0;
    for (uint8_t i = 0; i < strlen(in_s); i++ ) 
    {
        temp_c = in_s[i];
        if (temp_c == '.') 
        {
            out_ip[octet_p] = octet_i;
            octet_i = 0;
            octet_p += 1;
        } 
        else 
        {
            octet_i *= 10;
            octet_i += temp_c - '0';
        }
    }
    out_ip[octet_p] = octet_i;
}

int main()
{
	//Configure Network API
    Net_API_config_t NetAPIConfig; 
    strcpy(NetAPIConfig.S_interface, "enp0s3");
    strcpy(NetAPIConfig.S_DUT_HW_Address, MAC);
    strcpy(NetAPIConfig.S_DUT_IP_Address, IP_DUT);
    strcpy(NetAPIConfig.S_Tester_HW_Address, "6C:4B:90:79:0E:D1");
    strcpy(NetAPIConfig.S_Tester_IP_Address, IP_TESTER);
    Set_Network_Abstration_API_Config(NetAPIConfig);
	
    ICMPv4_config_t conf;
    strcpy(conf.DUT_IP, IP_DUT);
    strcpy(conf.TESTER_IP,IP_TESTER);
	conf.ICMP_IDENTIFIER = 0x69db;
	conf.ICMP_SEQUENCE_NUMBER = 0x0001;
	conf.INVALID_CHECKSUM = 0x0000;
	conf.FRAGMENT_REASSEMBLY_TIMEOUT = 15;
	conf.UNSUPPORTED_PROTOCOL = 0;
	conf.LISTEN_TIME = 3;
    Set_ICMPv4_Config(conf);


	 ip4addr ipv4;
    ipv4.dataLength = 4;
    stoiIP(IP_DUT, ipv4.Data);
	
    TP_OpenControlChannel(ipv4, 56000);


	ICMPv4_TYPE_04();
	ICMPv4_TYPE_05();
	ICMPv4_TYPE_08();
	ICMPv4_TYPE_09();
	ICMPv4_TYPE_10();
	ICMPv4_TYPE_11();
	ICMPv4_TYPE_12();
	ICMPv4_TYPE_16();
	ICMPv4_TYPE_18();
	ICMPv4_TYPE_22();
	TP_CloseControlChannel();
	return 0;
}
